package cn.phecda.boot.web.core.annotation;

import cn.phecda.boot.common.lang.constants.PropertyConstants;
import cn.phecda.boot.common.lang.util.EnvPropertyFinder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.lang.NonNull;

/**
 * <p> Swagger开启条件</p>
 *
 * @author : wanpinwei
 */
@Slf4j
public class SwaggerEnabledCondition implements Condition {
    @Override
    public boolean matches(@NonNull ConditionContext context, @NonNull AnnotatedTypeMetadata metadata) {
        String propertyName = PropertyConstants.PROPERTY_PREFIX_WEB_SWAGGER + PropertyConstants.PROPERTY_ENABLED;
        Boolean propertyValue = EnvPropertyFinder.getBoolean(context, propertyName);
        boolean matched = Boolean.TRUE.equals(propertyValue);

        if (log.isDebugEnabled()) {
            log.debug("|Phecda Boot Web|- The property [{}={}], the condition value [{}], mathced? {}", propertyName,
                    propertyValue,
                    Boolean.TRUE,
                    matched ? "Yes" : "No");
        }
        return matched;
    }
}
